Skip to content

Conversation

owenconti
Copy link
Contributor

@owenconti owenconti commented Aug 1, 2025

This should resolve #49

This PR adds support for providing default URL values during runtime via the frontend. This works by providing methods within the wayfinder.ts that user-land code can call to set (or add individual) default parameters. These parameters are stored in a global Wayfinder window object.

When generating the URL for a controller, we merge in any set default parameters, making sure that we don't override any keys already set during the calling of the url method.

Note: in theory we don't need to use a window object here, but when running the test suite, it seems like I was getting different instances of the wayfinder.ts file, the default parameters that were set were getting lost.

Usage

Here's how I have it set up in our app. The benefit here is it is up to the user to decide where and when to apply the defaults:

  setup({ el, App, props }) {
    const root = createRoot(el);

    setDefaultParameters({
      workspace: props.initialPage.props.workspace.slug
    });

    root.render(<App {...props} />);
  },

One thing I have not figured out with this approach is non-optional parameters that do not have a default set via the URL facade on the backend. Wayfinder doesn't know that domain parameter is being set as a default and will be applied/set during the url() call:

Screenshot 2025-08-01 at 8 42 53 AM

@owenconti owenconti force-pushed the default-parameters-frontend-support branch from 9a3deb4 to 722e0fc Compare August 1, 2025 14:51
@owenconti owenconti force-pushed the default-parameters-frontend-support branch from 722e0fc to 5ed96ae Compare August 1, 2025 14:59
@bdweix
Copy link

bdweix commented Aug 12, 2025

Nice work @owenconti - excited for this one!

@joetannenbaum
Copy link
Collaborator

Ok, this looks cool, thanks! Couple of adjustments/notes:

  • Renamed methods to align more clearly with backend methods
  • Instead of setting the defaults on the window, I set it as a local object in the module (just importing the wrong module in the test, that's why it wasn't working before)
  • For now, I removed the test regarding front end only defaults. The idea behind Wayfinder is that it should reflect your backend pretty directly, so having a front end default without a back end default feels off. That being said, these methods that you've added are helpful when the backend defaults are unable to be determined by Wayfinder (something completely dynamic at runtime), so you can manually provide them via JS.

Going to merge this in with the caveat that with the new Wayfinder changes coming down the pipeline in the next month or so these might change, just a heads up.

@joetannenbaum joetannenbaum merged commit ef4b9bb into laravel:main Aug 19, 2025
6 checks passed
@owenconti
Copy link
Contributor Author

Thank you for getting to this @joetannenbaum!

@joetannenbaum
Copy link
Collaborator

Of course! Thanks for your patience.

@n1crack
Copy link

n1crack commented Aug 31, 2025

@owenconti @joetannenbaum

Couldn't make it work.. Need to define locale value for the routes..

I think It's not possible to define default locale value for this right now. we need to define a dynamic prefix value like this..

https://github.com/mcamara/laravel-localization/?tab=readme-ov-file#usage

Route::group(
[
	'prefix' => LaravelLocalization::setLocale(),
	'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ]
], function(){ //...
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dealing with subdomains
4 participants